home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: RAND_MAX
- Date: 1 Apr 96 17:32:45 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.828379965@rscernix>
- References: <4jnr55$e6l@skivs.ski.org>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4jnr55$e6l@skivs.ski.org> gt@ns.oon.or.jp (Gemini Thunder) writes:
-
- >K&R2 says:
- > "rand returns a a pseudo-random integer in the range 0 to RAND_MAX,
- >which is at least 32767"
- >
- >It looks like RAND_MAX is not required to be the same as any other
- >limit (such as MAX_INT, etc.), that is fine, but why?
-
- To allow the implementor more freedom in choosing the rand() algorithm.
-
- >Wouldn't it be easier if RAND_MAX == MAX_INT or some other value?
- ^^^^^^^
- You meant INT_MAX, right?
-
- Huh??? Why would it be easier to write INT_MAX instead of RAND_MAX?
- One letter less to type? :-)
-
- >The reason I say this is how can you be sure your array will hold a
- >RAND_MAX sized integer, without some checking before hand, if RAND_MAX
- >is out there doing its own thing?
-
- I'm afraid I don't understand what you mean. Anyway, rand() returns
- an int, so it is guaranteed that RAND_MAX <= INT_MAX.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-